package com.cbj.db_work.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.joda.time.LocalDateTime;
import org.springframework.stereotype.Component;

/**
 * @author Godc
 * @description
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
//    @Override
//    public void insertFill(MetaObject metaObject) {
//        this.strictInsertFill(metaObject, "createDate", LocalDateTime.class, LocalDateTime.now());
//        this.strictInsertFill(metaObject, "modifiedDate", LocalDateTime.class, LocalDateTime.now());
////        this.setFieldValByName("modifiedDate", LocalDateTime.now(), metaObject);
////        this.setFieldValByName("isDelete",0,metaObject);
//
//    }
//
//    @Override
//    public void updateFill(MetaObject metaObject) {
//        this.strictUpdateFill(metaObject, "modifiedDate", LocalDateTime.class, LocalDateTime.now());
//    }

        @Override
        public void insertFill(MetaObject metaObject) {
            System.out.println("enter");

            this.strictInsertFill(metaObject, "createDate", LocalDateTime.class, LocalDateTime.now()); // 起始版本 3.3.0(推荐使用)

            this.strictInsertFill(metaObject, "operator", String.class, "cbj");
//            // 或者
//            this.strictInsertFill(metaObject, "createTime", () -> LocalDateTime.now(), LocalDateTime.class); // 起始版本 3.3.3(推荐)
//            // 或者
//            this.fillStrategy(metaObject, "createTime", LocalDateTime.now()); // 也可以使用(3.3.0 该方法有bug)
        }

        @Override
        public void updateFill(MetaObject metaObject) {

            this.strictUpdateFill(metaObject, "modifiedDate", LocalDateTime.class, LocalDateTime.now()); // 起始版本 3.3.0(推荐)
//            // 或者
//            this.strictUpdateFill(metaObject, "updateTime", () -> LocalDateTime.now(), LocalDateTime.class); // 起始版本 3.3.3(推荐)
//            // 或者
//            this.fillStrategy(metaObject, "updateTime", LocalDateTime.now()); // 也可以使用(3.3.0 该方法有bug)
        }
}
